package com.brillilab.service.core.experiments.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.brillilab.dao.mapper.experiments.ExperimentRelationMapper;
import com.brillilab.domain.po.experiments.ExperimentRelation;
import com.brillilab.service.core.experiments.IExperimentRelationService;

@Service
@Transactional
public class ExperimentRelationServiceImpl implements IExperimentRelationService {
	
	@Resource
	private ExperimentRelationMapper experimentRelationMapper;

	@Override
	public List<ExperimentRelation> getRelationList(List<Long> experimentIds) {
		return experimentRelationMapper.selectList(
                new LambdaQueryWrapper<ExperimentRelation>()
                        .in(ExperimentRelation::getExperimentId,experimentIds));
	}
	
	@Override
	public List<ExperimentRelation> selectList(Long experimentId) {
		LambdaQueryWrapper<ExperimentRelation> wrapper = new LambdaQueryWrapper<>();
		wrapper.eq(ExperimentRelation::getExperimentId, experimentId);
		return experimentRelationMapper.selectList(wrapper);
	}

	@Override
	public void insertBatch(List<ExperimentRelation> relationList) {
		if(CollectionUtils.isNotEmpty(relationList)){
			experimentRelationMapper.insertBatch(relationList);
		}
	}

	@Override
	public void delete(Long experimentId, List<Long> supIds) {
		LambdaQueryWrapper<ExperimentRelation> queryWrapper = new LambdaQueryWrapper<ExperimentRelation>();
		queryWrapper.eq(ExperimentRelation::getExperimentId, experimentId);
		if(CollectionUtils.isNotEmpty(supIds))
			queryWrapper.in(ExperimentRelation::getSupId, supIds);
		experimentRelationMapper.delete(queryWrapper);
	}
	
	
	
	
}
